#! /usr/bin/python3
# -*- coding: utf-8 -*-
# __author__ = "Fengxuewei"
# Date: 2020/6/22

# 1、常规的元组的定义方式。用[0]、[1]、[2]来索引，程序可读性差
#========================================================================================
tup1 = ('jim',16,'male','jim@sina.com')
tup2 = ('lucy',18,'female','lucy@163.com')
tup3 = ('liling',17,'male','liling@yahoo.com')
print(tup1[0],tup2[1],tup3[2])

if tup3[1]>=17:
    print(tup3[0])



#通过常量赋值的方式，给索引号固定的名称，程序的可读性强
#========================================================================================
name=0
age=1
gender=2
mail=3
print(tup1[name],tup2[age])


#通过namedtuple的方法
#========================================================================================

from collections import namedtuple

student = namedtuple('student',['name','age','sex','mail'])
s1=student('jim',16,'male','jim@sina.com')
s2=student('lucy',18,'female','lucy@163.com')
s3=student('liling',17,'male','liling@yahoo.com')
print(s1[name])
print(s2[age])
